<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- STYLESHEETS -->
    <!--[if lt IE 9]>
    <script src="../../js/flot/excanvas.min.js"></script>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
    <link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
    <link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
    <link rel="stylesheet" type="text/css" href="../../css/responsive.css">

    <link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- file-input -->
    <link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css" />
    <!-- SELECT2 -->
    <link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
    <!-- UNIFORM -->
    <link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
    <!-- datatable -->
    <link rel="stylesheet" href="../../js/datatables/datatable.css">
    <!-- WIZARD -->
    <link rel="stylesheet" type="text/css" href="../../js/bootstrap-wizard/wizard.css" />
    <link rel="stylesheet" href="../../js/datepicker/datepicker.css">
    <!-- FONTS
<link href='http://fonts.useso.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
-->
    <!-- file-input -->
    <link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css" />
    <!-- JQUERY -->
    <script src="../../js/jquery/jquery-2.0.3.min.js"></script>
    <script src="../../js/common.js"></script>

    <style>
        #main{
            min-height:70px;
            display: block;
        }
        .left {
            float: left;
            width: 45%;
        }

        .right {
            float: left;
            width: 55%;
            position: relative;
        }

        .floatDiv {
            width: 160px;
            height: 150px;
            border: 1px dotted blue;
            padding: 10px;
            position: relative;
            left: 65%;
            top: -45%;
        }
        .dataTables_scrollHeadInner {
          width: auto !important;
        }
        .dataTables_scrollHeadInner table {
          width:  100% !important;
        }
        .dataTables_scrollHeadInner table th {
          text-align: center;
        }
        .dataTables_scrollBody table td {
          text-align: center;
        }
        .dr-tip {
          color: red;
          margin-left: 8px;
          font-size: 16px;
        }
        .product_search label {
            margin-bottom: 0;
        }
        .product_search > div {
            margin-bottom: 10px;
        }
        .sreachProductName {
            display: flex;
            text-align: left;
            padding: 5px 0;
        }
        .sreachProductName img {
            width: 50px;
            height: 50px;
            border-radius: 4px;
        }
        .sreachProductName p{
            line-height: 25px;
            margin-left: 5px;
        }
        .detailSelect {
            width: 100%;
        }
    </style>
</head>

<body>
    <header class="navbar clearfix" id="header">
    </header>

    <!-- PAGE -->
    <section id="page">
        <!-- SIDEBAR -->
        <div id="sidebar" class="sidebar">
            <div class="sidebar-menu nav-collapse">

                <!-- SIDEBAR MENU -->
                <ul>

                </ul>
                <!-- /SIDEBAR MENU -->
            </div>

        </div>
        <!-- /SIDEBAR -->
        <div id="main-content">

            <div class="container" id="content">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="page-header">
                            <!-- STYLER -->
                            <!-- /STYLER -->
                            <!-- BREADCRUMBS -->
                            <ul class="breadcrumb">
                                <li>
                                    <i class="fa fa-home"></i>
                                    <a href="index.html">首页</a>
                                </li>
                                <li>
                                    <a href="#">商品管理</a>
                                </li>
                                <li>福袋管理</li>
                            </ul>
                            <!-- /BREADCRUMBS -->
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="modal fade bs-example-modal-lg" id="box-config" tabindex="-1" role="dialog"
                        aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog modal-lg" style="width: 1200px;">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <h4 class="modal-title">查询商品</h4>
                                </div>
                                <div class="modal-body">
                                    <div class="row">
                                        <label class="control-label col-md-2" style="line-height:34px;width:100px;">商品名称：</label>
                                        <div class="col-md-4" style="width:300px;">
                                            <input type="text" class="form-control searchProductName" placeholder="请输入商品名称" />
                                        </div>
                                        <div class="col-md-1" style="width:100px;">
                                            <span class="btn btn-primary search"><i class="fa fa-search"></i> 查询</span>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <table id="sreach_product_list" cellpadding="0" cellspacing="0" border="0"
                                            class="datatable table table-striped table-bordered table-hover">
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-12" style="padding-top: 20px">
                        <div class="detail_list form-group" style="clear: both">
                            <div class="box border primary">
                                <div class="box-title">
                                    <h4><i class="fa fa-bars"></i>商品查询</h4>
                                </div>
                                <div class="box-body big product_search" style="padding:10px;">
                                    <div>
                                        <label class="col-sm-1 control-label" style="width: auto;line-height: 34px;">选择销售的福袋产品</label>
                                        <a href="javaScript:;" class="btn btn-primary productSearch">
                                            <i class="fa fa-search"></i> 查询
                                        </a>
                                    </div>
                                    <div style='overflow:hidden' id="product_intr">
                                        <label class="col-sm-1 control-label" style="width: auto;line-height: 34px">已选销售的福袋产品:
                                            <span id='productName'></span></label>
                                        <label class="col-sm-1 control-label" style="width: auto;line-height: 34px">颜色:
                                            <span id="color"></span></label>
                                        <label class="col-sm-1 control-label" style="width: auto;line-height: 34px">SKU编码:
                                            <span id="skuCode"></span></label>
                                        <label class="col-sm-1 control-label" style="width: auto;line-height: 34px">尺码:
                                            <select id="sizeName">
                                            </select>
                                        </label>
                                        <div style="overflow:hidden; width: 100%">
                                            <label class="col-sm-1 control-label" style="width: auto;line-height: 34px">福袋发货SKU种类:</label>
                                            <div class="col-sm-1">
                                                <input type="text" class="form-control numberInput" placeholder="请输入福袋发货SKU种类" id="skuNum">
                                            </div>
                                            <label class="col-sm-1 control-label" style="width: auto;line-height: 34px">尺码过滤:</label>
                                            <div class="col-sm-1">
                                                <input type="text" class="form-control" placeholder="请输入尺码" id="sizeNameLimit">
                                            </div>
                                            <div class="col-sm-1">
                                                <span class="btn btn-primary" id="sizeNameLimitBtn">过滤</span>        
                                            </div>
                                        </div>
                                    </div>
                                    <div style="overflow:hidden; display:none;" id="product_none">
                                        <label class="col-sm-1 control-label" style="width: auto;line-height: 34px; color: red;">未选择销售的福袋产品
                                    </div>
                                </div>
                            </div>
                            <div class="box border primary">
                                <div class="box-title">
                                    <h4><i class="fa fa-bars"></i>明细查询</h4>
                                </div>
                                <div class="box-body big" style="padding:10px;">
                                    <label class="col-sm-1 control-label" style="width: auto;line-height: 34px">选择对应的发货明细</label>
                                    <a href="javaScript:;" class="btn btn-primary detailSearch">
                                        <i class="fa fa-search"></i> 查询
                                    </a>
                                </div>
                            </div>
                            <!-- <span class="point_info" style="color: darkred">(请导入变更后的全部明细)</span> -->
                            <div class="box border primary" style="margin-top: 15px">
                                <div class="box-title">
                                    <h4><i class="fa fa-table"></i>福袋明细</h4>
                                </div>
                                <div class="box-body" style="min-height: 200px">
                                    <table id="product_list" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">
                                    </table>
                                </div>
                            </div>
                            <div class="text-algin: center" style="padding-bottom:20px">
                                <a href="javascript:void(0)" class="btn-lg btn-primary btn-save" style="text-decoration: none">
                                    <i class="fa fa-save"></i> 保存
                                </a>
                            </div>
                        </div>
                    </div>
                    <!-- /CONTENT-->
                </div>
            </div>
        </div>
    </section>
    <!-- JQUERY -->
    <script src="../../js/jquery/jquery-2.0.3.min.js"></script>
    <script src="../../js/common.js"></script>
    <!-- JQUERY UI-->
    <script src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
    <!-- BOOTSTRAP -->
    <script src="../../bootstrap-dist/js/bootstrap.min.js"></script>
    <!-- SLIMSCROLL -->
    <script type="text/javascript" src="../../js/jQuery-slimScroll-1.3.0/jquery.slimscroll.min.js"></script>
    <script type="text/javascript" src="../../js/jQuery-slimScroll-1.3.0/slimScrollHorizontal.min.js"></script>
    <!-- BLOCK UI -->
    <script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
    <!--bootbox-->
    <script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
    <!-- AUTOSIZE -->
    <script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
    <!-- spinner -->
    <script src="../../js/spinner/spin.js"></script>
    <!-- bootstrap-fileupload -->
    <script type="text/javascript" src="../../js/jquery-upload/js/jquery.iframe-transport.js"></script>
    <script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload.min.js"></script>
    <script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-process.min.js"></script>
    <script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-validate.min.js"></script>

    <!-- INPUT MASK -->
    <script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>

    <!-- SELECT2 -->
    <script type="text/javascript" src="../../js/select2/select2.min.js"></script>
    <!-- UNIFORM -->
    <script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
    <!-- WIZARD -->
    <script src="../../js/bootstrap-wizard/jquery.bootstrap.wizard.min.js"></script>
    <!-- WIZARD -->
    <script src="../../js/jquery-validate/jquery.validate.min.js"></script>
    <script src="../../js/jquery-validate/additional-methods.min.js"></script>
    <script src="../../js/bootstrap-wizard/form-wizard.js"></script>
    <!-- NESTABLE LISTS -->
    <script type="text/javascript" src="../../js/nestable/jquery.nestable.min.js"></script>
    <!-- COOKIE -->
    <script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
    <!-- CUSTOM SCRIPT -->
    <script src="../../js/script.js"></script>

    <script src="../../js/Sortable.min.js"></script>

    <!-- DATA TABLES -->
    <script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
    <script type="text/javascript" src="../../js/datatables/datatable.js"></script>
    <script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
    <script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
    <script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>
    <script>
        var $mainDataTable = null;
        var sreachMode = 'product';
        var detailList = []
        var batchNo = null;
        var initDateTable = function () {
            var dtSetting = $.dataTableSetting({
                "serverSide": false,
                "bFilter": false, // 去掉搜索框
                "bLengthChange": true, // 每页显示数量						
                "sScrollX": "100%",
                "sScrollXInner": "100%",
                "paging": false,
                "data": detailList,
                "bSort": false,
                "aoColumns": [{
                    "mDataProp": "productName",
                    "sTitle": "商品名称",
                    "width": "18%"
                }, {
                    "mDataProp": "color",
                    "sTitle": "颜色",
                    "width": "12.5%"
                }, {
                    "sTitle": "SKU编码",
                    "width": "12.5%",
                    "mDataProp": "skuCode"
                }, {
                    "sTitle": "尺码",
                    "width": "12.5%",
                    "render": function (data, type, row) {
                        var skuList = row.skuList
                        var str = '<select class="detailSelect">'
                        for (let index = 0; index < skuList.length; index++) {
                            var item = skuList[index];
                            str += '<option stockCount=' + item.stockCount + ' skuCode=' + item.skuCode + ' value=' + item.sizeName + '>' + item.sizeName + '</option>'
                        }
                        str += '</select>'
                        return str;
                    }
                }, {
                    "sTitle": "分组",
                    "width": "8%",
                    "render": function (data, type, row) {
                        var str = '';
                        str += '<input type="tel" name="group" class="form-control numberInput" value="' + row.group +
                            '" placeholder="请输入分组">'
                        return str;
                    }
                }, {
                    "sTitle": "件数",
                    "width": "8%",
                    "render": function (data, type, row) {
                        var str = '';
                        str += '<input type="tel" name="count" class="form-control numberInput" value="' + row.count +
                            '" placeholder="请输入件数">'
                        return str;
                    }
                }, {
                    "sTitle": "优先级",
                    "width": "8%",
                    "render": function (data, type, row) {
                        var str = '';
                        str += '<input type="tel" name="priority" class="form-control numberInput" value="' + row.priority +
                            '" placeholder="请输入尺码">'
                        return str;
                    }
                }, {
                    "sTitle": "M站库存",
                    "width": "8%",
                    "mDataProp": "stockCount"
                }, {
                    "sTitle": "操作",
                    "width": "8%",
                    "render": function (data, type, row) {
                        var str = ''
                        str +=
                            "<a class='btn btn-danger btn-xs btn-width btn-delete' href='javascript:void(0)' billCode='" +
                            row.billCode + "'><i class='fa fa-trash-o'></i> 取消</a>"
                        return str;
                    }
                }]
            });
            $mainDataTable = $("#product_list").dataTable(dtSetting);
            $("select").select2();
        }
        var $productDataTable = null;
        var searchProduct = function () {
            var searchProductName = $(".searchProductName").val();
            var url = App.getContextPath() + "admin/stock/searchStockV2.do?productName=" + searchProductName;
            if ($productDataTable) {
                $productDataTable.api().ajax.url(url).load();
                return;
            }
            var dtSetting = $.dataTableSetting({
                "ajaxSource": url,
                "serverSide": false,
                "bFilter": false, // 去掉搜索框
                "bLengthChange": true, // 每页显示数量						
                "sScrollX": "100%",
                "sScrollXInner": "100%",
                "iDisplayLength": 10,
                "bSort": false,
                "aoColumns": [{
                    "mDataProp": "productName",
                    "sTitle": "商品名称",
                    "width": "40%",
                    "render": function (data, type, row) {
                        var str = '';
                        str += "<div class='sreachProductName'><img src='" + row.productImg +
                            "'><p>" + row.productName + "</p></div>"
                        return str;
                    }
                }, {
                    "mDataProp": "shortName",
                    "sTitle": "颜色",
                    "width": "20%"
                }, {
                    "sTitle": "尺码",
                    "mDataProp": "sizeName",
                    "width": "20%"
                }, {
                    "sTitle": "SKU编码",
                    "width": "12%",
                    "mDataProp": "skuCode"
                }, {
                    "sTitle": "操作",
                    "width": "8%",
                    "render": function (data, type, row) {
                        var skuCode = $('#skuCode').text()
                        var str = ''
                        if (sreachMode == 'product') {
                            if (skuCode == row.skuCode) {
                                str +=
                                    "<span class='btn btn-danger btn-qx'><i class='fa fa-trash-o'></i> 取消</span>"
                            } else {
                                str +=
                                    "<span class='btn btn-primary btn-xz'><i class='fa fa-check'></i> 选中</span>"
                            }
                        }
                        if (sreachMode == 'detail') {
                            if (hasDetail(row.skuCode)) {
                                str +=
                                    "<span class='btn btn-danger btn-qx' stockCount='" + row.amount + "'><i class='fa fa-trash-o'></i> 取消</span>"
                            } else {
                                str +=
                                    "<span class='btn btn-primary btn-xz' stockCount='" + row.amount +
                                    "'><i class='fa fa-check'></i> 选中</span>"
                            }
                        }
                        return str;
                    }
                }]
            });
            $productDataTable = $("#sreach_product_list").dataTable(dtSetting);
        }
        var hasDetail = function (skuCode) {
            var isHas = false
            for (let index = 0; index < detailList.length; index++) {
                const detail = detailList[index];
                if (skuCode == detail.skuCode) {
                    isHas = true
                    break;
                }
            }
            return isHas;
        }
        var searchPromotion = function (skuCode) {
            var url = App.getContextPath() + "admin/fortuneBag/findFortuneBagInfoByCopy.do?skuCode=" +
                skuCode;
            $.ajax({
                url: url,
                success: function (data) {
                    var data = data.extra[0]
                    $("#productName").text(data.productName)
                    var $sizeName = $("#sizeName")
                    var $str = ''
                    for (let index = 0; index < data.skuList.length; index++) {
                        var item = data.skuList[index];
                        $str += '<option skuCode=' + item.skuCode + ' value=' + item.sizeName + '>' + item.sizeName + '</option>'
                    }
                    console.log($str)
                    $sizeName.append($str);
                    $("#color").text(data.color)
                    $("#skuCode").text(skuCode)
                    $("#skuNum").val(data.bagSkuCount)
                    $("select").select2();
                }
            })
        }
        var searchBagDetail = function(skuCode, batchNo) {
            var sizeName = $('#sizeNameLimit').val();
            var url = App.getContextPath() + "admin/fortuneBag/findFortuneBagDetailByCopy.do?skuCode=" +
                skuCode + '&batchNo=' + batchNo + '&sizeName=' + sizeName
                $.ajax({
                url: url,
                success: function (data) {
                    var data = data.extra;
                    for (let index = 0; index < data.length; index++) {
                        const item = data[index];
                        item.skuCode = item.skuList[0].skuCode
                        item.stockCount = item.skuList[0].stockCount
                    }
                    detailList = data
                    initDateTable(detailList)
                }
            })
        }
        var searchDei
        var saveBag = function (fortuneBags) {
            $.ajax({
                url: App.getContextPath() + 'admin/fortuneBag/saveBatch.do',
                type: 'POST',
                data: {
                    fortuneBags: fortuneBags
                },
                success: function (result) {
                    if (result.type == "success") {
                        var message = batchNo ? '编辑福袋成功!' : '创建福袋成功!'
                        $("#product_list").empty();
                        $("#skuNum").val('')
                        $('#skuCode').text('')
                        $("#product_intr").hide();
                        $("#product_none").show();
                        detailList = []
                        batchNo = null
                        $(".product_search div").eq(0).show()
                        $.alert(message);
                    } else {
                        $.alert(result.content);
                    }
                }
            })
        }
        var deleteDetail = function (skuCode) {
            for (var index = 0; index < detailList.length; index++) {
                var item = detailList[index];
                if (item.skuCode == skuCode) {
                    detailList.splice(index, 1)
                }
            }
            initDateTable(detailList)
        }
        var init = function () {
            App.init();
            var skuCode = $.getUrlParam('skuCode')
            var batchNo = $.getUrlParam('batchNo')
            if (skuCode && batchNo) {
                searchPromotion(skuCode)
                searchBagDetail(skuCode, batchNo)
            } else {
                $('#product_intr').hide()
                $("#product_none").show()
            }
            $('.productSearch').click(function () {
                sreachMode = 'product'
                searchProduct()
                $("#box-config").modal("show");
            })
            $('.detailSearch').click(function () {
                sreachMode = 'detail'
                searchProduct()
                $("#box-config").modal("show");
            })
            $("#product_list").on('click', '.btn-delete', function () {
                var $this = $(this)
                $.confirm("确认取消此福袋明细?", function () {
                    var skuCode = $this.closest('tr').find('td').eq(2).text();
                    deleteDetail(skuCode)
                });
            })
            $('body').on('keyup', '.numberInput', function() {
                var $val = $(this).val()
                $(this).val($val.replace(/^(0+)|[^\d]+/g,''))
                var $name = $(this).attr('name')
                if ($name) {
                    var index = $(this).closest('tr').index()
                    detailList[index][$name] = $val.replace(/^(0+)|[^\d]+/g,'')
                }
            })
            $("body").on('click', '.btn-save', function () {
                var skuCode = $('#skuCode').text()
                var skuNum = $("#skuNum").val()
                if (!skuCode) {
                    $.alert('请先选择销售福袋的商品!')
                    return false
                }
                if (!skuNum) {
                    $.alert('请先输入福袋发货SKU种类!')
                    return false
                }
                if (!$("#product_list").find('tr').length) {
                    $.alert('请先选择福袋明细!')
                    return false
                }
                var $this = $(this)
                var arr = []
                var isNot = false
                $("#product_list").find('tbody tr').each(function (index, ele) {
                    var $ele = $(ele)
                    var td = $ele.find('td')
                    var srcSkuCode = td.eq(2).text()
                    var group = td.eq(4).find('input').val()
                    var count = td.eq(5).find('input').val()
                    var priority = td.eq(6).find('input').val()
                    if (!group || !count || !priority) {
                        isNot = true
                    }
                    var obj = {
                        skuCode: skuCode,
                        srcSkuCode: srcSkuCode,
                        group: group,
                        count: count,
                        priority: priority,
                        bagSkuCount: skuNum
                    }
                    if (batchNo) {
                        obj.batchNo = batchNo
                    }
                    arr.push(obj)
                })
                if (isNot) {
                    $.alert('分组、件数、优先级不能为空！')
                    return false
                }
                $.confirm("确认保存吗?", function () {
                    saveBag(JSON.stringify(arr))
                });
            })
            $('body').on('click', '.btn-qx', function () {
                if (sreachMode == 'product') {
                    $('#skuCode').text('')
                    $('#product_intr').hide()
                    $("#product_none").show();
                }
                if (sreachMode == 'detail') {
                    var $this = $(this)
                    var $td = $this.closest('tr').find('td');
                    var skuCode = $td.eq(3).text()
                    deleteDetail(skuCode)
                }
                $(this).removeClass('btn-qx')
                    .removeClass('btn-danger')
                    .addClass('btn-xz')
                    .addClass('btn-primary')
                    .html("<i class='fa fa-check'></i> 选中")
            })
            $('body').on('click', '.btn-xz', function () {
                var $this = $(this)
                var $td = $this.closest('tr').find('td');
                var skuCode = $td.eq(3).text()
                var color = $td.eq(1).text()
                var productName = $td.eq(0).find('p').text()
                var sizeName = $td.eq(2).text()
                var stockCount = $this.attr('stockCount')
                if (sreachMode == 'product') {
                    $('.btn-qx').removeClass('btn-qx')
                        .removeClass('btn-danger')
                        .addClass('btn-xz')
                        .addClass('btn-primary')
                        .html("<i class='fa fa-check'></i> 选中")
                    $('#productName').text(productName)
                    $('#color').text(color)
                    $('#skuCode').text(skuCode)
                    $('#sizeName').html('<option selected skucode=' + skuCode + ' value=' + sizeName + '>' + sizeName + '</option>')
                    $('#product_intr').show()
                    $("#product_none").hide();
                    $("select").select2();
                }
                if (sreachMode == 'detail') {
                    var obj = {
                        productName: productName,
                        color: color,
                        skuCode: skuCode,
                        group: '',
                        count: '',
                        priority: '',
                        skuList: [{
                            sizeName: sizeName,
                            stockCount: stockCount,
                            skuCode: skuCode
                        }],
                        stockCount: stockCount
                    }
                    if (batchNo) {
                        obj.batchNo = batchNo
                    }
                    
                    detailList.push(obj)
                    initDateTable(detailList)
                }
                $this.removeClass('btn-xz')
                    .removeClass('btn-primary')
                    .addClass('btn-qx')
                    .addClass('btn-danger')
                    .html("<i class='fa fa-trash-o'></i> 取消")
            })
            $('.search').click(function () {
                searchProduct()
            })
            $('body').on('change','.detailSelect', function(){
               var index = $(this).closest('tr').index()
               var $option = $(this).find("option:selected")
               var $skuCode = $option.attr('skuCode')
               var $stockcount = $option.attr('stockcount')
               $(this).closest('tr').find('td').eq(2).text($skuCode)
               $(this).closest('tr').find('td').eq(7).text($stockcount)
               detailList[index].skuCode = $skuCode
               detailList[index].stockcount = $stockcount
            //    console.log(detailList)
            //    initDateTable()
            })
            $('body').on('change','#sizeName', function(){
                var index = $(this).closest('tr').index()
               var $option = $(this).find("option:selected")
               var $skuCode = $option.attr('skuCode')
               $("#skuCode").text($skuCode)
            })
            $("#sizeNameLimitBtn").click(function() {
                searchBagDetail($.getUrlParam('skuCode'), $.getUrlParam('batchNo'))
            })
        }
        $(function () {
            $("#header").load("../head.html");
            init();
        });
    </script>

    <!-- /JAVASCRIPTS -->
</body>

</html>